package com.school.sdk.haikang.helper;

import com.school.sdk.haikang.CommonMethod.osSelect;
import lombok.SneakyThrows;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;

@RestController
@RequestMapping("/postAlarm")
public class PostAlarmHelpController {

    @GetMapping("/picFile/{fileName}")
    @SneakyThrows
    public void prodPic(@PathVariable String fileName, HttpServletResponse response) {
        response.setContentType(MediaType.IMAGE_JPEG_VALUE);
        File file = new File((osSelect.isLinux() ? PostAlarmDataUtils.linuxPicBasePath : PostAlarmDataUtils.winPicBasePath).concat(fileName));
        if (!file.exists()) {
            return;
        }
        FileInputStream inputStream = new FileInputStream(file);
        PostAlarmDataUtils.writeImageFile(response, inputStream);
        inputStream.close();
    }
}
